<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属部门" prop="sysOrgCode">
        <el-input
          v-model="queryParams.sysOrgCode"
          placeholder="请输入所属部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校" prop="school">
        <el-input
          v-model="queryParams.school"
          placeholder="请输入学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学院" prop="college">
        <el-input
          v-model="queryParams.college"
          placeholder="请输入学院"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="major">
        <el-input
          v-model="queryParams.major"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级" prop="clazz">
        <el-input
          v-model="queryParams.clazz"
          placeholder="请输入班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年级" prop="grade">
        <el-input
          v-model="queryParams.grade"
          placeholder="请输入年级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学院ID" prop="collegeId">
        <el-input
          v-model="queryParams.collegeId"
          placeholder="请输入学院ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校ID" prop="schoolId">
        <el-input
          v-model="queryParams.schoolId"
          placeholder="请输入学校ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业ID" prop="majorId">
        <el-input
          v-model="queryParams.majorId"
          placeholder="请输入专业ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级ID" prop="clazzId">
        <el-input
          v-model="queryParams.clazzId"
          placeholder="请输入班级ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班主任" prop="headteacher">
        <el-input
          v-model="queryParams.headteacher"
          placeholder="请输入班主任"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班主任电话" prop="headteacherTel">
        <el-input
          v-model="queryParams.headteacherTel"
          placeholder="请输入班主任电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班委" prop="headstudent">
        <el-input
          v-model="queryParams.headstudent"
          placeholder="请输入班委"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班委电话" prop="headstudentTel">
        <el-input
          v-model="queryParams.headstudentTel"
          placeholder="请输入班委电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签发日期" prop="issuanceDate">
        <el-date-picker clearable
                        v-model="queryParams.issuanceDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择签发日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="学年" prop="schoolYear">
        <el-input
          v-model="queryParams.schoolYear"
          placeholder="请输入学年"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总价" prop="pricesum">
        <el-input
          v-model="queryParams.pricesum"
          placeholder="请输入总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="书目清单图片" prop="booklistPic">
        <el-input
          v-model="queryParams.booklistPic"
          placeholder="请输入书目清单图片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['oldsystem:booklist:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['oldsystem:booklist:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['oldsystem:booklist:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['oldsystem:booklist:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="booklistList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id"/>
      <el-table-column label="所属部门" align="center" prop="sysOrgCode"/>
      <el-table-column label="编号" align="center" prop="code"/>
      <el-table-column label="名称" align="center" prop="name"/>
      <el-table-column label="学校" align="center" prop="school"/>
      <el-table-column label="学院" align="center" prop="college"/>
      <el-table-column label="专业" align="center" prop="major"/>
      <el-table-column label="班级" align="center" prop="clazz"/>
      <el-table-column label="年级" align="center" prop="grade"/>
      <el-table-column label="学院ID" align="center" prop="collegeId"/>
      <el-table-column label="学校ID" align="center" prop="schoolId"/>
      <el-table-column label="专业ID" align="center" prop="majorId"/>
      <el-table-column label="班级ID" align="center" prop="clazzId"/>
      <el-table-column label="班主任" align="center" prop="headteacher"/>
      <el-table-column label="班主任电话" align="center" prop="headteacherTel"/>
      <el-table-column label="班委" align="center" prop="headstudent"/>
      <el-table-column label="班委电话" align="center" prop="headstudentTel"/>
      <el-table-column label="签发日期" align="center" prop="issuanceDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.issuanceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="其它" align="center" prop="other"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="学年" align="center" prop="schoolYear"/>
      <el-table-column label="总价" align="center" prop="pricesum"/>
      <el-table-column label="书目清单图片" align="center" prop="booklistPic"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['oldsystem:booklist:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['oldsystem:booklist:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改老系统数目清单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属部门" prop="sysOrgCode">
          <el-input v-model="form.sysOrgCode" placeholder="请输入所属部门"/>
        </el-form-item>
        <el-form-item label="编号" prop="code">
          <el-input v-model="form.code" placeholder="请输入编号"/>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称"/>
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入学校"/>
        </el-form-item>
        <el-form-item label="学院" prop="college">
          <el-input v-model="form.college" placeholder="请输入学院"/>
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业"/>
        </el-form-item>
        <el-form-item label="班级" prop="clazz">
          <el-input v-model="form.clazz" placeholder="请输入班级"/>
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入年级"/>
        </el-form-item>
        <el-form-item label="学院ID" prop="collegeId">
          <el-input v-model="form.collegeId" placeholder="请输入学院ID"/>
        </el-form-item>
        <el-form-item label="学校ID" prop="schoolId">
          <el-input v-model="form.schoolId" placeholder="请输入学校ID"/>
        </el-form-item>
        <el-form-item label="专业ID" prop="majorId">
          <el-input v-model="form.majorId" placeholder="请输入专业ID"/>
        </el-form-item>
        <el-form-item label="班级ID" prop="clazzId">
          <el-input v-model="form.clazzId" placeholder="请输入班级ID"/>
        </el-form-item>
        <el-form-item label="班主任" prop="headteacher">
          <el-input v-model="form.headteacher" placeholder="请输入班主任"/>
        </el-form-item>
        <el-form-item label="班主任电话" prop="headteacherTel">
          <el-input v-model="form.headteacherTel" placeholder="请输入班主任电话"/>
        </el-form-item>
        <el-form-item label="班委" prop="headstudent">
          <el-input v-model="form.headstudent" placeholder="请输入班委"/>
        </el-form-item>
        <el-form-item label="班委电话" prop="headstudentTel">
          <el-input v-model="form.headstudentTel" placeholder="请输入班委电话"/>
        </el-form-item>
        <el-form-item label="签发日期" prop="issuanceDate">
          <el-date-picker clearable
                          v-model="form.issuanceDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择签发日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="其它" prop="other">
          <el-input v-model="form.other" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="学年" prop="schoolYear">
          <el-input v-model="form.schoolYear" placeholder="请输入学年"/>
        </el-form-item>
        <el-form-item label="总价" prop="pricesum">
          <el-input v-model="form.pricesum" placeholder="请输入总价"/>
        </el-form-item>
        <el-form-item label="书目清单图片" prop="booklistPic">
          <el-input v-model="form.booklistPic" placeholder="请输入书目清单图片"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addBooklist, delBooklist, getBooklist, listBooklist, updateBooklist} from "@/api/oldsystem/booklist";

export default {
  name: "OldBooklist",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 老系统数目清单表格数据
      booklistList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysOrgCode: null,
        code: null,
        name: null,
        school: null,
        college: null,
        major: null,
        clazz: null,
        grade: null,
        collegeId: null,
        schoolId: null,
        majorId: null,
        clazzId: null,
        headteacher: null,
        headteacherTel: null,
        headstudent: null,
        headstudentTel: null,
        issuanceDate: null,
        other: null,
        schoolYear: null,
        pricesum: null,
        booklistPic: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询老系统数目清单列表 */
    getList() {
      this.loading = true;
      listBooklist(this.queryParams).then(response => {
        this.booklistList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sysOrgCode: null,
        code: null,
        name: null,
        school: null,
        college: null,
        major: null,
        clazz: null,
        grade: null,
        collegeId: null,
        schoolId: null,
        majorId: null,
        clazzId: null,
        headteacher: null,
        headteacherTel: null,
        headstudent: null,
        headstudentTel: null,
        issuanceDate: null,
        other: null,
        remark: null,
        schoolYear: null,
        pricesum: null,
        booklistPic: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加老系统数目清单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBooklist(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改老系统数目清单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBooklist(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBooklist(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除老系统数目清单编号为"' + ids + '"的数据项？').then(function () {
        return delBooklist(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oldsystem/booklist/export', {
        ...this.queryParams
      }, `booklist_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
